//
//  SinglePictureViewCell.m
//  Logistics
//
//  Created by 刘峰 on 2017/12/11.
//  Copyright © 2017年 com.Logistics. All rights reserved.
//

#import "SinglePictureViewCell.h"

@interface SinglePictureViewCell ()

@property (nonatomic, strong) PHAsset *asset;

@end

@implementation SinglePictureViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    /*
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(movePicture:)];
    [self.singleImage addGestureRecognizer:pan];
     */
}

- (void)movePicture:(UIPanGestureRecognizer *)sender {
    if ([self.delegate respondsToSelector:@selector(moveOutPictureAction:)]) {
        [self.delegate moveOutPictureAction:sender];
    }
}

- (IBAction)chooseImageAction:(UIButton *)sender {    
    if ([self.delegate respondsToSelector:@selector(selectedPictureAsset:Sender:)]) {
        [self.delegate selectedPictureAsset:self.asset Sender:sender];
    }
}


- (void)photoAsset:(PHAsset *)asset Original:(BOOL)isOriginal imageOption:(NSMutableDictionary *)option {
    _asset         = asset;
    UIImage *image = option[asset.localIdentifier];
    
    if (image) {
        _singleImage.image = image;
    }else {

        if (isOriginal) {
            [asset getOriginalImageFromIClound:^(UIImage *image, BOOL isOriginal) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    _singleImage.image = image;
                    if (isOriginal) {
                        [option setValue:image forKey:asset.localIdentifier];
                    }
                });
            }];
            
        }else {
            [asset getThumbImageWithiMageSize:CGSizeMake(KscreenWidth/2, KscreenWidth/2) AssetBlock:^(UIImage *image) {
                _singleImage.image = image;
                [option setValue:image forKey:asset.localIdentifier];
            }];
        }
        
    }
}

@end
